<template>
  <div>

    <el-card shadow="never">
      <!-- 搜索表单 -->
      <UserSearch @search="reload"
                  @tabIndex="tabIndex" />
      <!-- 数据表格 -->
      <div class="selectTime flex-align-center"
           v-if="pay_type==2">
        <ul class="timeTab"
            v-for="(item, index) in orderStatusArr"
            :key="index">
          <li :class="[currentIndex == index ? 'active' : '']"
              @click="switchTimeTab(item.id,item.value,index)">{{ item.value }}</li>
        </ul>
      </div>
      <div class="selectTime flex-align-center"
           v-if="pay_type==1">
        <ul class="timeTab"
            v-for="(item, index) in orderStatusArrs"
            :key="index">
          <li :class="[currentIndex == index ? 'active' : '']"
              @click="switchTimeTabs(item.id,item.value,index)">{{ item.value }}</li>
        </ul>
      </div>
      <ele-pro-table ref="table"
                     :columns="columns"
                     :datasource="datasource"
                     :selection.sync="selection"
                     tool-class="ele-toolbar-form"
                     row-key="id">
        <!-- 表头工具栏 -->
        <template v-slot:toolbar>

        </template>

        <template v-slot:img="{ row }">
          <div><img class="categoryImages"
                 :src="row.img"
                 alt="" /></div>
        </template>
        <template v-slot:operate_type="{ row }">
          <el-link :underline="false"
                   type="success">
            {{ operateType(row.operate_type) }}
          </el-link>
        </template>
        <template v-slot:pay_method="{ row }">
          <el-link :underline="false"
                   :type="serviceStatusType(row.pay_method)?.types">
            {{ serviceStatusType(row.pay_method).text }}
          </el-link>
        </template>
        <template v-slot:amount="{ row }">
          {{ Number(row.amount)}}

        </template>
        <template v-slot:name="{ row }">
          {{ row.name?row.name:'--' }}

        </template>
        <template v-slot:status="{ row }">
          <el-switch :active-value="1"
                     :inactive-value="2"
                     v-model="row.status"
                     @change="editStatus(row)" />
        </template>
        <!-- 状态列 -->

        <template v-slot:discount_money="{ row }">
          <div>
            {{ row.discount_money }}
          </div>
        </template>
        <template v-slot:sort="{ row }">
          <i class="sort-handle el-icon-rank ele-text-secondary"
             style="cursor: move"></i>
          <div v-if="false">{{ row }}</div>
        </template>
        <!-- 操作列 -->
        <template v-slot:action="{ row }">
          <el-link type="primary"
                   :underline="false"
                   icon="el-icon-edit"
                   @click="openEdit(row)">
            查看详情
          </el-link>

          <!-- <el-popconfirm class="ele-action"
                         title="确定要删除该条信息？"
                         @confirm="remove(row)">
            <template v-slot:reference>
              <el-link type="danger"
                       :underline="false"
                       icon="el-icon-delete">
                删除
              </el-link>
            </template>
          </el-popconfirm> -->
        </template>
      </ele-pro-table>
    </el-card>
    <!-- 编辑弹窗 -->
    <role-edit :data="current"
               :drawerEditBoolen.sync="drawerEditBoolen"
               @done="reload" />
    <!-- 权限分配弹窗 -->
  </div>
</template>
	
	<script>


// import RoleSearch from './components/role-search';
// import Sortable from 'sortablejs';
import RoleEdit from './role-edit.vue';

import UserSearch from '../components/user-search.vue';
import { amountLog } from '@/api/financialManagement/index'
import { upClassify } from '@/api/classifyList/index'
// import {
//   sitecCategoriesDelete,
//   siteCategoriesList,
//   siteCategoriesModify,
//   siteCategoriesDetail,
//   siteBatchCategoriesDelete
// } from '@/api/serviceManagement/categoriesList';
export default {
  name: 'Recharge',
  components: {
    UserSearch,
    RoleEdit
  },
  props: {
    active: String
  },
  data () {
    return {
      pay_type: '1',
      currentIndex: 0,
      orderStatusArrs: [{
        value: '全部',
        id: 0
      },
      {
        value: '微信',
        id: 1
      },

      {
        value: '支付宝',
        id: 2
      },
      {
        value: '余额',
        id: 4
      },
      ],
      orderStatusArr: [
        {
          value: '全部',
          id: 0
        },
        {
          value: '微信',
          id: 1
        },

        {
          value: '支付宝',
          id: 2
        },

        {
          value: '现金',
          id: 3
        },

        {
          value: '余额',
          id: 4
        },
        {
          value: 'pos机',
          id: 5
        },

      ],
      // 表格列配置
      columns: [

        // {
        //   prop: 'id',
        //   label: '排序',
        //   sortable: 'custom',
        //   showOverflowTooltip: true,
        //   minWidth: 30,
        //   align: 'center',
        //   slot: 'sort'
        // },
        {
          columnKey: 'index',
          type: 'index',
          label: '序号',

          align: 'center',
          showOverflowTooltip: false,

        },

        {
          prop: 'wachat_nickname',
          label: '用户名称',


          align: 'center',
          showOverflowTooltip: true,

        },
        {
          prop: 'operate_type',
          label: '消费类型',


          align: 'center',
          showOverflowTooltip: true,
          slot: 'operate_type'
        },
        {
          prop: 'amount',
          label: '支付金额',
          align: 'center',


          showOverflowTooltip: true,
          slot: 'amount'

        },
        {
          prop: 'order_sn',
          label: '订单编号',


          showOverflowTooltip: false,

          align: 'center'
        },
        {
          prop: 'give_amount',
          label: '赠送金额',
          align: 'center',
          sortable: 'custom',

          showOverflowTooltip: true,

        },
        {
          prop: 'pay_method',
          label: '支付方式',
          align: 'center',
          sortable: 'custom',

          showOverflowTooltip: true,
          slot: 'pay_method'
        },
        {
          prop: 'name',
          label: '操作人员',
          sortable: 'custom',
          align: 'center',
          showOverflowTooltip: true,
          slot: 'name'
        },
        {
          prop: 'create_time',
          label: '创建时间',
          align: 'center',
          sortable: 'custom',
          showOverflowTooltip: false,
          formatter: (_row, _column, cellValue) => {
            return this.$util.toDateString(cellValue, 'yyyy-MM-dd HH:mm');
          }
        },
        {
          columnKey: 'action',
          label: '操作',

          align: 'center',
          resizable: false,
          slot: 'action',
          hideInSetting: true,
          showOverflowTooltip: true
        }
      ],

      // 表格选中数据
      selection: [],
      // 当前编辑数据
      current: null,

      // 是否显示编辑弹窗
      drawerEditBoolen: false,
      // 是否显示导入弹窗
      showAuth: false,
      showChoose: false
    };
  },

  activated () {
    this.reload();
  },
  computed: {
    operateType: function () {
      return function (status) {
        let orderStatus = '';
        // status订单状态（0.待付款 1.待接单 2.已接单 3.服务中 4.已完成 5.已取消/退款)
        // orderStatus =
        //   status == 1 ? '余额充值' : status == 2 ? '购买商品' : '购买套餐 ';

        orderStatus =
          status == 1 ? '微信在线充值余额' : status == 2 ? '微信线下扫码充值' : status == 3 ? '支付宝线下充值余额' : status == 4
            ? '现金充值余额' : status == 5 ? 'pos机充值余额' : status == 6 ? '微信在线扫码充值余额' : status == 7 ? '支付宝在线扫码充值余额'
              : status == 8 ? '微信在线购买商品' : status == 9 ? '余额购买商品' : status == 10 ? '微信在线购买套餐卡' : status == 11 ? '余额购买套餐卡'
                : status == 12 ? '微信线下购买套餐卡' : status == 13 ? '支付宝线下购买套餐卡' : status == 14 ? '现金购买套餐卡' : status == 15 ? 'pos购买套餐卡'
                  : status == 16 ? '微信在线扫码购买套餐卡' : status == 17 ? '支付宝在线扫码购买套餐卡' : status == 18 ? '微信在线购买商品退款' : status == 19 ? '余额购买商品退款'
                    : status == 20 ? '手动操作余额' : status == 21 ? '余额线下消费' : status == 22 ? '微信线下消费' : status == 23 ? '支付宝线下消费' : status == 24 ? '现金线下消费' : status == 25 ?
                      'pos线下消费' : status == 26 ? '微信在线消费' : '支付宝在线消费';
        return orderStatus;
      };
    },
    // operateType () {
    //   return function (operateType) {

    //     if (operateType == 1) {
    //       return {
    //         text: '充值余额',
    //         types: 'success'
    //       };
    //     } else if (operateType == 2) {
    //       return {
    //         text: '商城',
    //         types: ''
    //       };
    //     } else if (operateType == 3) {
    //       return {
    //         text: '套餐卡',
    //         types: 'danger'
    //       };
    //     }
    //   };
    // },

    // 服务状态
    serviceStatusType () {
      return function (serviceType) {

        if (serviceType == 1) {
          return {
            text: '微信',
            types: 'success'
          };
        } else if (serviceType == 2) {
          return {
            text: '支付宝',
            types: ''
          };
        } else if (serviceType == 3) {
          return {
            text: '现金',
            types: 'danger'
          };
        } else if (serviceType == 4) {
          return {
            text: '余额',
            types: 'danger'
          };
        } else {
          return {
            text: 'pos机',
            types: 'warning'
          };
        }
      };
    },
  },
  watch: {
    active (value) {
      this.$nextTick(() => {
        console.log(value)
        this.pay_type = value
        this.reload({
          pay_type: value
        });
      });
    },
    immediate: true
  },
  methods: {
    switchTimeTab (i, val, index) {
      this.currentIndex = index;
      console.log(i, val)
      this.reload({
        pay_method: i,
        pay_type: this.pay_type
      });
    },
    tabIndex (index) {
      this.$emit('searchIndex', index);
    },
    switchTimeTabs (i, val, index) {
      this.currentIndex = index;
      console.log(i, val)
      this.reload({
        pay_method: i,
        pay_type: this.pay_type
      });
    },
    // rowDrop () {
    //   const tbody = document.querySelector('.el-table__body-wrapper tbody');
    //   const _this = this;
    //   Sortable.create(tbody, {
    //     forceFallback: true,
    //     dragClass: 'drag',
    //     delay: 100,
    //     animation: 1000,
    //     onEnd ({ newIndex, oldIndex }) {
    //       console.log(newIndex);
    //       console.log(oldIndex);
    //       //更换表格数据 后续拖动坐标才会正确
    //       let data = _this.$refs.table.getData();

    //       let nid = data[newIndex].id;
    //       let oid = data[oldIndex].id;

    //       const currRow = data.splice(oldIndex, 1)[0];
    //       data.splice(newIndex, 0, currRow);

    //       console.log(data);

    //       //   sortChange(data)
    //       //     .then((msg) => {

    //       //     })
    //       //     .catch((e) => {
    //       //       _this.$refs.table.reload();
    //       //     });

    //       //去数据库更换排序

    //       console.log(_this.$refs.table.getData());
    //     }
    //   });
    // },

    /* 表格数据源 */
    datasource ({ page, limit, where }) {
      console.log(where)
      return amountLog({
        page,
        limit,
        pay_type: "1",
        ...where,

      });
    },
    /* 刷新表格 */
    reload (where) {

      this.$refs.table.reload({ page: 1, where });
    },
    /* 显示编辑 */
    async openEdit (row) {
      console.log(row);
      if (row?.id) {
        // const res = await siteCategoriesDetail(row.id);

        this.current = row;
        // 用户余额管理
        this.drawerEditBoolen = !this.drawerEditBoolen;
      } else {
        this.drawerEditBoolen = !this.drawerEditBoolen;
        this.current = null;
      }
    },

    /* 更改状态 */
    editStatus (row) {
      const loading = this.$loading({ lock: true });
      upClassify({
        id: row.id,
        status: row.status,

      })
        .then((msg) => {
          console.log(msg)
          loading.close();
          this.$message.success(msg.msg);
          this.reload();
        })
        .catch((e) => {
          loading.close();
          row.status = !row.status ? 1 : 2;
          this.$message.error(e.message);
        });
    },

    /* 显示分配权限 */
    openAuth (row) {
      this.current = row;
      this.showAuth = true;
    },
    /* 删除 */
    // remove (row) {
    //   const loading = this.$loading({ lock: true });
    //   sitecCategoriesDelete(row.id)
    //     .then((msg) => {
    //       loading.close();
    //       this.$message.success(msg);
    //       this.reload();
    //     })
    //     .catch((e) => {
    //       loading.close();
    //       this.$message.error(e.message);
    //     });
    // },
    /* 批量删除 */
    // removeBatch () {
    //   if (!this.selection.length) {
    //     this.$message.error('请至少选择一条数据');
    //     return;
    //   }
    //   console.log(this.selection);
    //   this.$confirm('确定要删除选中的信息吗?', '提示', {
    //     type: 'warning'
    //   })
    //     .then(() => {
    //       const loading = this.$loading({ lock: true });
    //       console.log(this.selection.map((d) => d.id));
    //       siteBatchCategoriesDelete(this.selection.map((d) => d.id))
    //         .then((msg) => {
    //           loading.close();
    //           this.$message.success(msg);
    //           this.reload();
    //         })
    //         .catch((e) => {
    //           loading.close();
    //           this.$message.error(e.message);
    //         });
    //     })
    //     .catch(() => { });
    // }
  }
};
	</script>
	
	<style lang="less">
.selectTime {
  display: flex;
  align-items: center;
  margin-bottom: 20px;
  .timeTab {
    display: flex;
    align-items: center;
    margin-right: 20px;
    li {
      list-style-type: none;
      display: block;
      width: 110px;
      height: 38px;
      line-height: 38px;
      text-align: center;
      border: 1px solid #d9d9d9;
      border-radius: 10px;
    }
    .active {
      width: 110px;
      height: 38px;
      border-radius: 6px;
      background: #1890ff;
      color: #fff;
      text-align: center;
      line-height: 38px;
    }
  }
  .orderStatus {
    min-width: 77px;
    height: 34px;
    font-size: 14px;
    line-height: 34px;
  }
  .filterDate {
    text-align: center;
    line-height: 34px;
    width: 90px;
    height: 34px;
    font-size: 14px;
    border-radius: 2px 0px 0px 2px;
    border: 1px solid #d9d9d9;
    border-right: none;
  }
  .ele-fluid {
    width: 300px !important;
  }
}
.categoryImages {
  width: 50px;
  height: 50px;
}
</style>
	